package com.shiguiwu.springmybatis.javabase.thread;

import lombok.extern.slf4j.Slf4j;

/**
 * @description: volatile 可见性
 * @author: stone
 * @date: Created by 2021/6/19 21:12
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.thread
 */
@Slf4j
public class VolatileTests {

    public volatile static boolean flag = true;

    public static void main(String[] args) throws InterruptedException {

      new Thread(() -> {
            System.out.println("线程正在执行==========>");
            while (flag) {
//                System.out.println("循环===============>");会清空工作内存
//                log.error("循环===============>");
            }

            System.out.println("end=================>");
        }).start();

        Thread.sleep(1000);
        flag = false;
        System.out.println("主线程接受");

    }
}




